"""
@author: wy
@file: 验证密码复杂性.py
@time: 2023/11/27 17:07
"""
import re

def pwdtest(pwd):
    score = 2
    # 判断密码长度是否大于8
    if len(pwd) < 9:
        print("密码长度必须超过8位")
    else:
        score += 1

    # 判断密码是否由至少三种不同字符构成
    upper_count = 0
    lower_count = 0
    digit_count = 0
    other_count = 0
    for s in pwd:
        if s.isupper() and upper_count == 0:
            upper_count = 1
        elif s.islower() and lower_count == 0:
            lower_count = 1
        elif s.isdigit() :
            digit_count = 1
        elif other_count == 0 :
            other_count = 1
    if upper_count +lower_count+digit_count+other_count > 2:
        score += 1
    else:
        print("密码必须由大、小写字母、数字以及其他符合以上四种至少三种组成")

    # 判断密码是否有长度超过或等于3的子串重复
    flag = 1
    for i in range(len(pwd)-5):
        repeatstr = pwd[i:i+3]
        if repeatstr in pwd[i+3:]:
            print("密码有长度超过或等于3的子串重复")
            flag = 0
            break
    if flag == 1:
        score += 1
    return score

passwrd = input("请设置你的密码：")
print(f"该密码的复杂评分等级为：%d 分"%(pwdtest(passwrd)))

